package com.vm.activity;

import com.android.volley.RequestQueue;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.StringRequest;
import com.vm.commons.VMConst;
import com.vm.utils.MyVolley;
import com.wwtscapp.apk.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class SetNewPsdActivity extends Activity{
	protected static final String TAG = null;
	ImageView imgbtn_back;
	EditText et_pass;
	EditText et_pass2;
	Button btn_sure;
	String userId;
	private RequestQueue mQueue;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login_new_pssword);
		mQueue = MyVolley.getRequestQueue();
		userId=getIntent().getStringExtra("userId");
		init();
	}
	public void init(){
		imgbtn_back=(ImageView)findViewById(R.id.imgbtn_search_back);
		et_pass=(EditText)findViewById(R.id.et_pass);
		et_pass2=(EditText)findViewById(R.id.et_pass2);
		btn_sure=(Button)findViewById(R.id.btn_sure);
		imgbtn_back.setOnClickListener(btn_backListener);
		btn_sure.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String pass=et_pass.getText().toString();
				String pass2=et_pass2.getText().toString();
				if(pass.equals("")||pass2.equals("")){
					Toast toast = Toast.makeText(SetNewPsdActivity.this, "输入不能为空",
							Toast.LENGTH_SHORT);
					toast.show();
				}else if(!pass.equals(pass2)){
					Toast toast = Toast.makeText(SetNewPsdActivity.this, "两次密码输入不一致",
							Toast.LENGTH_SHORT);
					toast.show();
				}else{
					String url = VMConst.REQUEST_URL + "changePwd?id="
							+ userId + "&password=" + pass;
					try{
						StringRequest stringRequest = new StringRequest(url,
								new Listener<String>() {

									@Override
									public void onResponse(String arg0) {
										// TODO Auto-generated method stub
										Toast toast = Toast.makeText(
												SetNewPsdActivity.this, "修改密码成功",
												Toast.LENGTH_SHORT);
										toast.show();
										Intent intent=new Intent(SetNewPsdActivity.this,LoginActivity.class);
										startActivity(intent);
										finish();
									}
							
						},null);
						mQueue.add(stringRequest);
					}catch (Exception e) {
						// TODO Auto-generated catch block
						Log.e(TAG, e.getMessage());
					}
				}
			}
		});
	}
	OnClickListener btn_backListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			onBackPressed();
		}
	};

	/**
	 * 手机自带返回按钮监听
	 */
	@Override
	public void onBackPressed() {
		super.onBackPressed();

	}

}